package com.fq.myapplication.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fq.myapplication.R;
import com.fq.myapplication.adapter.CommentAdapter;
import com.fq.myapplication.bean.CommentItem;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import java.util.List;

public class CommentFragment extends BottomSheetDialogFragment {

    private ListView commentListView;
    private CommentAdapter commentAdapter;

    @NonNull
    @Override
    public BottomSheetDialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        dialog.getWindow().setDimAmount(0f); // 设置遮罩透明度为 0，即完全透明
        
        // 设置固定高度为屏幕高度的三分之二
        dialog.getBehavior().setPeekHeight((int) (getResources().getDisplayMetrics().heightPixels * 0.67));
        dialog.getBehavior().setHideable(false); // 禁止下拉隐藏
        dialog.getBehavior().setDraggable(false); // 禁止拖动
        
        return dialog;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_comment, container, false);
        
        // 初始化ListView
        commentListView = view.findViewById(R.id.comment_list);
        
        // 获取示例数据
        List<CommentItem> commentItems = CommentItem.getDefaultList();
        
        // 创建并设置适配器
        commentAdapter = new CommentAdapter(getContext(), commentItems);
        commentListView.setAdapter(commentAdapter);
        
        return view;
    }
}    